package com.example.springbootbook2.mapper;

import com.example.springbootbook2.model.BookInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    @Select("select * from book_info where status!=0 order by id desc limit #{offset},#{pageSize}")
    List<BookInfo> getBookInfoByPage(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize);

    @Select("select count(1) from book_info where status!=0")
    Integer getTotal();

    @Insert("insert into book_info(book_name,author,count,price,publish,status)" +
            "values(#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer addBook(BookInfo bookInfo);

    @Select("select * from book_info where id=#{id}")
    BookInfo queryBookInfoById(Integer id);

    Integer updateBook(BookInfo bookInfo);

    @Update("update book_info set status=0 where id=#{id}")
    Integer deleteBook(Integer id);

    Integer batchDelete(List<Integer> ids);
}
